<?php
/**
 * 
 * 菜单信息
 * xysc users Version1.0
 * ==================================
 * Copy 2016-2017
 * Web:www.xjh7.com
 * ==================================
 * Author:lj
 * Date:2016-03-09
 * model() 创建模型对象，静态
 * tableName() 返回表名
*/

class Menu extends CActiveRecord {
	/**
	 *返回当前模型对象的方法 
	 */
	public static function model($className = __CLASS__){
		return parent::model($className);
	}
	/**
	 * 返回当前表名
	 */
	public function tableName(){
		return '{{pages}}';
	}
	 
	/**
	 * 查询所有父pages
	 */
	public function allParent(){
		$sql = "SELECT * FROM {{pages}} WHERE pages_parent=0 AND active=1 ORDER BY pages_order ASC";
		$result = self::model()->findAllBySql($sql);
		return $result;
	}
	
	/**
	 * 条件查询pages
	 */
	public function queryPages($pages_name,$pages_parent){
		$sql = "SELECT * FROM {{pages}} WHERE active=1 ";
		if($pages_name!=null&&$pages_name!="")
		{
			$sql.= " AND pages_name like '%".$pages_name."%'";
		}
		if($pages_parent!=null&&$pages_parent!="")
		{
			$sql.= " AND pages_parent =".$pages_parent;
		}
		$sql.= " order by pages_parent ";
		$result = self::model()->findAllBySql($sql);
		return $result;
	}	
	
	/**
	 * @author xjh
	 * 根据id查询page信息
	 */
	public function getPageInfoByPageId($pages_id){
		
		$cmodel = new CCCModel();
		$sql = "SELECT * FROM {{pages}} WHERE pages_id=$pages_id";
		$result = $cmodel -> sel($sql);
		return $result;
		
	}
	
	/**
	 * 修改菜单信息方法
	 * @author xjh
	 * @param int $pages_id
	 */
	public function updatePageInfoById($pages_id){
		$cmodel = new CCCModel();
		$sql = "UPDATE {{pages}} set pages_parent='".$_POST['pages_parent']."',pages_name='".$_POST['pages_name']."',pages_address='".$_POST['pages_address']."',pages_order='".$_POST['pages_order']."' WHERE pages_id=$pages_id";
		$result = $cmodel -> upd($sql);
		return $result;
	}
	/**
	 * 删除菜单信息方法
	 * @author xjh
	 * @param int $pages_id
	 */
	public function deletePageInfoById($pages_id){
		$cmodel = new CCCModel();
		$sql = "UPDATE {{pages}} set active = 0 WHERE pages_id=$pages_id";
		$result = $cmodel -> upd($sql);
		return $result;
	}
	
	
}
	
?>